def _main():
    def build_conversion_map():
        lower = [chr(i) for i in range(ord("A"), ord("Z") + 1)]
        upper = [chr(i) for i in range(ord("a"), ord("z") + 1)]
        result = dict(zip(lower, upper))
        result.update(zip(upper, lower))
        return result

    conversion_map = build_conversion_map()

    line_count = 0
    new_lined = True
    with open("T1.txt", "r") as file_input, open("T2.txt", "w") as file_output:
        while True:
            c = file_input.read(1)
            if len(c) == 0:
                break
            if new_lined:
                line_count += 1
                new_lined = False
            if c == "\n":
                new_lined = True
            c = conversion_map.get(c, c)
            file_output.write(c)
    print(f"共 {line_count} 行（不计末尾最后一空行）")


if __name__ == "__main__":
    _main()
